﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;


namespace MovieSystem.Banco
{
    public class EntTarifa
    {
        private int intTarifaId = 0;
        private string strTarifaTecnologia = "";
        private double dblTarifaValor = 0;

        
        /// <summary>
        /// Id
        /// </summary>
        public int Id
        {

            get { return intTarifaId; }
            set { intTarifaId = value; }

        }

        public string Tecnologia
        {

            get { return strTarifaTecnologia; }
            set { strTarifaTecnologia = value; }

        }

        public double Valor
        {

            get { return dblTarifaValor; }
            set { dblTarifaValor = value; }

        }

        public Boolean Inserir()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("Insert into tarifa (tecnoTarifa, valorTarifa) values ('" + this.Tecnologia +"', " + this.Valor + ");", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }
            

            return true;

        }

        public Boolean Alterar()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("update tarifa set tecnoTarifa= '" + this.Tecnologia + "', valorTarifa = " + this.Valor + " where idTarifa = " + this.Id +";", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public Boolean Excluir()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("delete from tarifa where idTarifa = " + this.Id + ";", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public EntTarifa BuscaPorId(string parametro)
        {
            EntTarifa oTarifa = new EntTarifa();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM tarifa where idTarifa =" + parametro + "", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    oTarifa = new EntTarifa();
                    oTarifa.Id = Convert.ToInt32(reader["idTarifa"].ToString());
                    oTarifa.Tecnologia = reader["tecnoTarifa"].ToString();
                    oTarifa.Valor = Convert.ToDouble(reader["valorTarifa"].ToString());

                }

                EntConexao.FecharConexao();
            }
            return oTarifa;
        }

        public List<EntTarifa> BuscaPorParametro(string parametro)
        {
            List<EntTarifa> lTarifas = new List<EntTarifa>();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM tarifa where tecnoTarifa='" + parametro + "'", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    EntTarifa oTarifa = new EntTarifa();
                    oTarifa.Id = Convert.ToInt32(reader["idTarifa"].ToString());
                    oTarifa.Tecnologia = reader["tecnoTarifa"].ToString();
                    oTarifa.Valor = Convert.ToDouble(reader["valorTarifa"].ToString());
                    lTarifas.Add(oTarifa);

                }

                EntConexao.FecharConexao();
            }
            return lTarifas;
        }

        public List<EntTarifa> BuscaTodas()
        {
            List<EntTarifa> lTarifas = new List<EntTarifa>();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM tarifa;", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    EntTarifa oTarifa = new EntTarifa();
                    oTarifa.Id = Convert.ToInt32(reader["idTarifa"].ToString());
                    oTarifa.Tecnologia = reader["tecnoTarifa"].ToString();
                    oTarifa.Valor = Convert.ToDouble(reader["valorTarifa"].ToString());
                    lTarifas.Add(oTarifa);

                }

                EntConexao.FecharConexao();
            }
            return lTarifas;
        }
    }
}
